package controllers;

import java.util.*;

import javax.servlet.http.HttpServletRequest;

import models.game.Game;
import models.players.Player;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import utils.GenericValidationAndOptions;
import utils.PlayerValidationAndOptions;

@Controller
public class ActionOpionsController {

	@RequestMapping("/ShowActionOptions")
	public synchronized String showActionOptions(HttpServletRequest request) {

		// Saves the selected action from ActivePage.jsp to the session for
		// further use
		String action = request.getParameter("action");
		request.getSession().setAttribute("action", action);

		// Gets the player and game objects from the session to be used as
		// parameters in the Options methods
		Player player = (Player) request.getSession().getAttribute("player");
		Game game = (Game) request.getSession().getAttribute("game");

		// Calls the corresponding method for the selected action
		switch (action) {
		case "Drive":

			// Sets as session attribute a list with the available options,
			// provided by the method
			request.getSession().setAttribute("actionOptionsList",
					driveOpitions(player, game));
			break;

		case "DirectFlight":
			request.getSession().setAttribute("actionOptionsList",
					directFlightOpitions(player, game));
			break;

		case "CharterFlight":
			request.getSession().setAttribute("actionOptionsList",
					charterFlightOpitions(player, game));
			break;

		case "ShuttleFlight":
			request.getSession().setAttribute("actionOptionsList",
					shuttleFlightOpitions(player, game));
			break;

		case "BuildResearchStation":
			request.getSession().setAttribute("actionOptionsList",
					buildResearchStationOpitions(player, game));
			break;

		case "TreatDisease":
			request.getSession().setAttribute("actionOptionsList",
					treatDiseaseOpitions(player, game));
			break;

		case "DiscoverACure":
			request.getSession().setAttribute("actionOptionsList",
					discoverACureOpitions(player, game));
			break;

		case "RecieveKnowledge":
			request.getSession().setAttribute("actionOptionsList",
					recieveKnowledgeOptions(player, game));
			break;

		case "ShareKnowledge":
			request.getSession().setAttribute("actionOptionsList",
					shareKnowledgeOptions(player, game));
			break;

		case "EndTurn":
			request.getSession().setAttribute("actionOptionsList",
					endTurn(player, game));
			break;

		default:
			break;
		}

		return "/ActiveOptionsPage";
	}

	// Now unnecessary and repetitive, to be refactored once roles are implemented
	public ArrayList<String> driveOpitions(Player player, Game game) {
		if (true) {
			return GenericValidationAndOptions.driveOpitions(player, game);
		} else {
			return null;
		}
	}

	public ArrayList<String> directFlightOpitions(Player player, Game game) {
		if (true) {
			return GenericValidationAndOptions.directFlightOpitions(player,
					game);
		} else {
			return null;
		}
	}

	public ArrayList<String> charterFlightOpitions(Player player, Game game) {
		if (true) {
			return GenericValidationAndOptions.charterFlightOpitions(player,
					game);
		} else {
			return null;
		}
	}

	public ArrayList<String> shuttleFlightOpitions(Player player, Game game) {
		if (true) {
			return GenericValidationAndOptions.shuttleFlightOpitions(player,
					game);
		} else {
			return null;
		}
	}

	public ArrayList<String> buildResearchStationOpitions(Player player,
			Game game) {
		if (true) {
			return GenericValidationAndOptions.buildResearchStationOpitions(
					player, game);
		} else {
			return null;
		}
	}

	public ArrayList<String> treatDiseaseOpitions(Player player, Game game) {
		if (true) {
			return GenericValidationAndOptions.treatDiseaseOpitions(player,
					game);
		} else {
			return null;
		}
	}

	public ArrayList<String> discoverACureOpitions(Player player, Game game) {
		if (true) {
			return GenericValidationAndOptions.discoverACureOpitions(player,
					game);
		} else {
			return null;
		}
	}

	public ArrayList<String> recieveKnowledgeOptions(Player player, Game game) {
		if (true) {
			return GenericValidationAndOptions.recieveKnowledgeOptions(player,
					game);
		} else {
			return null;
		}
	}

	public ArrayList<String> shareKnowledgeOptions(Player player, Game game) {
		if (true) {
			return GenericValidationAndOptions.shareKnowledgeOptions(player,
					game);
		} else {
			return null;
		}
	}

	public synchronized ArrayList<String> endTurn(Player player, Game game) {
		ArrayList<String> list = new ArrayList<String>();
		list.add("Confirm EndTurn");
		return list;
	}
}
